<script setup>
import * as echarts from 'echarts';
import { onMounted } from 'vue';

const NowDate = function(){
  const NewDate = new Date()
  const year = NewDate.getFullYear()
  let month = NewDate.getMonth() + 1
  let day = NewDate.getDate()
  month = month < 10 ? '0' + month : month
  day = day < 10 ? '0' + day : day
  const NOW_MONTHS_AGO = `${year}-${month}-${day}`
  return NOW_MONTHS_AGO
}


onMounted(() => {
  // 基于准备好的dom，初始化echarts实例
  const myChart = echarts.init(document.getElementById('box1'));
  // 绘制图表
  myChart.setOption({
    title: {
      text: '千峰学生来源',
      subtext: NowDate(),
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '50%',
        data: [
          { value: 1048, name: '搜索引擎' },
          { value: 735, name: '直接访问' },
          { value: 580, name: '邮件营销' },
          { value: 484, name: '广告联盟' },
          { value: 300, name: '视频广告' }
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  })


  const myChart2 = echarts.init(document.getElementById('box2'));
  // 绘制图表
  myChart2.setOption({
    title: {
      text: '千峰学生来源',
      subtext: NowDate(),
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '50%',
        data: [
          { name: '北京', value: 215 },
          { name: '广西', value: 117 },
          { name: '江苏', value: 2150 },
          { name: '上海', value: 135 },
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  })

  const myChart3 = echarts.init(document.getElementById('box3'));
  // 绘制图表
  myChart3.setOption({
    title: {
      text: '千峰男女比例分布',
      subtext: NowDate(),
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '50%',
        data: [
          { name: '男', value: 852 },
          { name: '女', value: 628 },
          { name: '保密', value: 437 },
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  })


})


</script>
<template>
  <div class="echars">
    <div id="box1"></div>
    <div id="box2"></div>
    <div id="box3"></div>
  </div>
</template>

<style scoped>
#box1,
#box2,
#box3 {
  width: 800px;
  height: 400px;
  /* background-color: white; */
}

.echars {
  display: flex;
  justify-content: space-between;
}
</style>